package com.kaifamiao.www.demo.do0826;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class Demo02 {
    public static void main(String[] args) {
        /**
         * 1,筛选所有姓“张”的人
         * 2，筛选名字有三个字的人
         * 3，最后对结果进行打印输出
         */
        List<String> list = new ArrayList<>();
        list.add("张无忌");
        list.add("周芷若");
        list.add("赵敏");
        list.add("张三");
        list.add("张三丰");
//        //获取stream
//        Stream<String> stream = list.stream();
//        //数据过滤
//        Stream<String> zhangStream = stream.filter(s -> s.startsWith("张"));
//        Stream<String> lengthStream = zhangStream.filter(s -> s.length() == 3);
//        //迭代
//        lengthStream.forEach(s -> System.out.println(s));

        //链式调用
        list.stream().filter(e ->e.startsWith("张"))
                .filter(e -> e.length() == 3)
                .forEach(e -> System.out.println(e));
        System.out.println(list);
        list.stream().filter(e ->e.startsWith("张"))
                .filter(e -> e.length() == 3)
                .forEach(new  Consumer<String>(){
                    @Override
                    public void accept(String s) {
                        System.out.println(s);
                    }
                });
        Consumer c = s -> System.out.println(s);
        Consumer c1 = new  Consumer<String>(){
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        System.out.println("-------");
        List<String> names = new ArrayList<>();
        for (String s : list){
            if (s.startsWith("张")&&s.length()==3){
                names.add(s);
            }
        }
        System.out.println(names);
    }
}
